<%@ page import="com.xszx.entity.TUser" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 32312
  Date: 2024/1/9
  Time: 10:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%
    TUser user = (TUser)request.getSession().getAttribute("user");
%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title></title>

    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link rel="stylesheet" href="/resource/materialize/css/materialize.min.css" media="screen,projection" />
    <!-- Bootstrap Styles-->
    <link href="/resource/css/bootstrap.css" rel="stylesheet" />
    <!-- FontAwesome Styles-->
    <link href="/resource/css/font-awesome.css" rel="stylesheet" />
    <!-- Morris Chart Styles-->
    <link href="/resource/js/morris/morris-0.4.3.min.css" rel="stylesheet" />
    <!-- Custom Styles-->
    <link href="/resource/css/custom-styles.css" rel="stylesheet" />
    <!-- Google Fonts-->
    <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
    <link rel="stylesheet" href="/resource/js/Lightweight-Chart/cssCharts.css">
    <script src="/resource/js/jquery-1.7.1.js"></script>

</head>
<body>
<div id="wrapper">
    <nav class="navbar navbar-default top-navbar" role="navigation">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle waves-effect waves-dark" data-toggle="collapse" data-target=".sidebar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand waves-effect waves-dark" href="/jsp/index.jsp"><i class="large material-icons">insert_chart</i> <strong>TRACK</strong></a>
            <div id="sideNav" href=""><i class="material-icons dp48">toc</i></div>
        </div>

        <ul class="nav navbar-top-links navbar-right">
            <li><a class="dropdown-button waves-effect waves-dark" href="#!" data-activates="dropdown1"><i class="fa fa-user fa-fw"></i> <b>${user.username}</b> </a></li>
        </ul>
    </nav>
    <!-- Dropdown Structure -->
    <ul id="dropdown1" class="dropdown-content">
        <li><a href="/jsp/form.jsp"><i class="fa fa-user fa-fw"></i> 个人中心</a>
        </li>
        <li><a href="/jsp/personCenter.jsp"><i class="fa fa-bell fa-fw"></i> 个人任务</a>
        </li>
        <li><a href="/jsp/test.jsp" target="_top"><i class="fa fa-sign-out fa-fw"></i> 注销</a>
        </li>
    </ul>
    <ul id="dropdown2" class="dropdown-content w250">
        <li>
            <a href="#">
                <div>
                    <i class="fa fa-comment fa-fw"></i> New Comment
                    <span class="pull-right text-muted small">4 min</span>
                </div>
            </a>
        </li>
        <li class="divider"></li>
        <li>
            <a href="#">
                <div>
                    <i class="fa fa-twitter fa-fw"></i> 3 New Followers
                    <span class="pull-right text-muted small">12 min</span>
                </div>
            </a>
        </li>
        <li class="divider"></li>
        <li>
            <a href="#">
                <div>
                    <i class="fa fa-envelope fa-fw"></i> Message Sent
                    <span class="pull-right text-muted small">4 min</span>
                </div>
            </a>
        </li>
        <li class="divider"></li>
        <li>
            <a href="#">
                <div>
                    <i class="fa fa-tasks fa-fw"></i> New Task
                    <span class="pull-right text-muted small">4 min</span>
                </div>
            </a>
        </li>
        <li class="divider"></li>
        <li>
            <a href="#">
                <div>
                    <i class="fa fa-upload fa-fw"></i> Server Rebooted
                    <span class="pull-right text-muted small">4 min</span>
                </div>
            </a>
        </li>
        <li class="divider"></li>
        <li>
            <a class="text-center" href="#">
                <strong>See All Alerts</strong>
                <i class="fa fa-angle-right"></i>
            </a>
        </li>
    </ul>
    <!--/. NAV TOP  -->
    <nav class="navbar-default navbar-side" role="navigation">
        <div class="sidebar-collapse">
            <ul class="nav" id="main-menu">

                <li>
                    <a class="active-menu waves-effect waves-dark" href="/jsp/index.jsp"><i class="fa fa-dashboard"></i> 统计</a>
                </li>

                <li>
                    <a href="#" class="waves-effect waves-dark"><i class="fa fa-sitemap"></i>固定资产管理<span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level">
                        <li>
                            <a href="#">资产管理<span class="fa arrow"></span></a>
                            <ul class="nav nav-third-level">
                                <li>
                                    <a href="/jsp/assetTable.jsp">总资产管理</a>
                                </li>
                                <li>
                                    <a href="/jsp/assetFixTable.jsp">维修资产</a>
                                </li>
                                <li>
                                    <a href="/jsp/assetForbiddenTable.jsp">禁用资产</a>
                                </li>
                                <li>
                                    <a href="/jsp/assetFreeTable.jsp">空闲资产</a>
                                </li>
                                <li>
                                    <a href="/jsp/assetScrapTable.jsp">报废资产</a>
                                </li>
                                <li>
                                    <a href="/jsp/assetUsingTable.jsp">使用中资产</a>
                                </li>
                            </ul>
                        </li>
                        <li>
                            <a href="/jsp/recordTable.jsp">合同管理</a>
                        </li>
                        <li>
                            <a href="#">系统管理<span class="fa arrow"></span></a>
                            <ul class="nav nav-third-level">
                                <li>
                                    <a href="/jsp/deptTable.jsp">部门管理</a>
                                </li>
                                <li>
                                    <a href="/jsp/user.jsp">用户管理</a>
                                </li>
                                <li>
                                    <a href="/jsp/roleTable.jsp">角色管理</a>
                                </li>
                                <li>
                                    <a href="/jsp/menuTable.jsp">菜单管理</a>
                                </li>
                            </ul>

                        </li>
                    </ul>
                </li>
                <li>
                    <a href="/jsp/empty.jsp" class="waves-effect waves-dark"><i class="fa fa-fw fa-file"></i> 日志</a>
                </li>
            </ul>

        </div>

    </nav>
    <!-- /. NAV SIDE  -->
    <div id="page-wrapper" >
        <div class="header">
            <h1 class="page-header">
                用户管理
            </h1>
            <ol class="breadcrumb">
                <li><a href="#">Home</a></li>
                <li><a href="#">部门管理</a></li>
                <li class="active">数据</li>
            </ol>

        </div>

        <div id="page-inner">

            <div class="row">
                <div class="col-md-12">
                    <!--    Hover Rows  -->
                    <div class="card">
                        <div class="card-action">
                            <button class=btn signin_btn data-toggle=modal data-target=.add value="+data[i].did+">添加</button>


                            <div class="input-field inline" style="width: 200px">
                                用户名称：<input type="text" id="checkid" style="width: 100px">
                            </div>
                            <div class="input-field inline" style="width: 200px">
                                用户账号：<input type="text" id="checkname"style="width: 100px">
                            </div>
                            <div class="input-field inline" style="width: 200px">
                                用户部门： <select class="form-control" name="signin_aintodepts" id="signin_aintodepts" placeholder="选择部门">
                                              <option value="选择部门" >选择部门</option>
                            </select>
                            </div>
                            <div class="input-field inline" style="width: 200px">
                                用户性别：
                                <input name="sexss" type="radio" id="test1"  value="1" />
                                <label for="test1" style="font-size: 15px">男</label>
                                <input name="sexss" type="radio" id="test2"  value="2"/>
                                <label for="test2" style="font-size: 15px">女</label>
                            </div>
                            <button class=btn signin_btn data-toggle=modal id="check">查询</button>
                        </div>

                        <div class="card-content">
                            <div class="table-responsive">
                                <table class="table table-hover">
                                    <thead>
                                    <tr>
                                        <th>编号</th>
                                        <th>姓名</th>
                                        <th>职位</th>
                                        <th>部门</th>
                                        <th>性别</th>
                                        <th>年龄</th>
                                        <th>电话号码</th>
                                        <th>身份证号</th>
                                        <th>email</th>
                                        <th>地址</th>
                                        <th>账号</th>
                                        <th>密码</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody name="deptTable">
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <!-- End  Hover Rows  -->
                </div>
            </div>



            <footer><p>Copyright &copy; 2016.Company name All rights reserved.<a target="_blank" href="http://sc.chinaz.com/moban/">&#x7F51;&#x9875;&#x6A21;&#x677F;</a></p></footer>
        </div>
        <!-- /. PAGE INNER  -->
        <div class="modal fade update" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
            <div class="modal-dialog modal-lg" role="document">
                <div class="modal-content">
                    <div class="sign-content">

                        <div class="modal-header">
                            <h2>编辑</h2>
                        </div><!--/.modal-header -->

                        <div class="modal-body">
                            <div class="signin-form">
                                <div class=" ">
                                    <div class=" ">
                                        <div class="signin-footer" id="updatee">
                                            <div class="form-group">
                                                <label for="upid" style="font-size: 20px">用户编号</label>
                                                <input type="text" name="username" class="form-control" id="upid" readonly>
                                            </div>
                                            <div class="form-group">
                                                <label for="username" style="font-size: 20px">用户名称</label>
                                                <input type="text" name="username" class="form-control" id="upusername" >
                                            </div><!--/.form-group -->
                                            <div class="form-group">
                                                <label for="signin1"style="font-size: 20px">职位</label>
                                               <select class="form-control" name="signin1" id="signin1" >
                                                <option value="选择职位" >选择职位</option>
                                               </select>
                                            </div><!--/.form-group -->
                                            <div class="form-group">
                                                <label for="signin_aintodepts2"style="font-size: 20px">部门</label>
                                                 <select class="form-control" name="signin_aintodepts2" id="signin_aintodepts2" placeholder="选择部门">
                                                <option value="选择部门" >选择部门</option>
                                            </select>
                                            </div>
                                            <div class="form-group" id="sexxxx">
                                                <label for="sexx"style="font-size: 20px">性别</label>
                                                <input name="sexx" type="radio" id="test3"  value="1" />
                                                <label for="test3" style="font-size: 15px">男</label>
                                                <input name="sexx" type="radio" id="test5"  value="2"/>
                                                <label for="test5" style="font-size: 15px">女</label>
                                            </div><!--/.form-group -->
                                            <div class="form-group">
                                                <label for="age"style="font-size: 20px">年龄</label>
                                                <input type="text" name="dsum" class="form-control" id="upage" >
                                            </div><!--/.form-group -->
                                            <div class="form-group">
                                                <label for="phone"style="font-size: 20px">电话号码</label>
                                                <input type="text" name="dname" class="form-control" id="upphone" >
                                            </div><!--/.form-group -->
                                            <div class="form-group">
                                                <label for="idcard"style="font-size: 20px">身份证号</label>
                                                <input type="text" name="dsum" class="form-control" id="upidcard" >
                                            </div><!--/.form-group -->
                                            <div class="form-group">
                                                <label for="email"style="font-size: 20px">email</label>
                                                <input type="text" name="dname" class="form-control" id="upemail" >
                                            </div><!--/.form-group -->
                                            <div class="form-group">
                                                <label for="upaddres"style="font-size: 20px">地址</label>
                                                <input type="text" name="dsum" class="form-control" id="upaddres" >
                                            </div><!--/.form-group -->
                                            <div class="form-group">
                                                <label for="account"style="font-size: 20px">账号</label>
                                                <input type="text" name="dname" class="form-control" id="upaccount" >
                                            </div><!--/.form-group -->
                                            <div class="form-group">
                                                <label for="password"style="font-size: 20px">密码</label>
                                                <input type="text" name="dsum" class="form-control" id="uppassword" >
                                            </div><!--/.form-group -->
                                            <button type="submit" id="update" class="btn signin_btn" data-toggle="modal" data-target=".signin_modal">
                                                修改
                                            </button>
                                        </div>
                                    </div><!--/.col -->
                                </div><!--/.row -->

                            </div><!--/.signin-form -->

                        </div><!--/.modal-body -->

                    </div><!--/.sign-content -->
                </div><!--/.modal-content -->
            </div><!--/.modal-dialog -->
        </div><!--/.modal -->
        #        添加用户
        <div class="modal fade add" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
            <div class="modal-dialog modal-lg" role="document">
                <div class="modal-content">
                    <div class="sign-content">

                        <div class="modal-header">
                            <h2>添加</h2>
                        </div><!--/.modal-header -->

                        <div class="modal-body">
                            <div class="signin-form">
                                <div class=" ">
                                    <div class=" ">
                                        <div class="form-group">
                                            <label for="username" style="font-size: 20px">用户名称</label>
                                            <input type="text" name="username" class="form-control" id="username" >
                                        </div><!--/.form-group -->
                                        <div class="form-group">
                                            <label for="signin2"style="font-size: 20px">职位</label>
                                            <select class="form-control" name="signin"  id="signin2">
                                            <option value="选择职位" >选择职位</option>
                                        </select>
                                            <div class="form-group">
                                                <label for="signin_aintodepts1"style="font-size: 20px">部门</label>
                                                用户部门： <select class="form-control" name="signin_aintodepts1" id="signin_aintodepts1" placeholder="选择部门">
                                                <option value="选择部门" >选择部门</option>
                                                </select>
                                        </div><!--/.form-group -->
                                        <div class="form-group" id="sexx">
                                            <label for="test6"style="font-size: 20px">性别</label>
                                            <input name="sexxx" type="radio" id="test6"  value="1" />
                                            <label for="test6" style="font-size: 15px">男</label>
                                            <input name="sexxx" type="radio" id="test7"  value="2"/>
                                            <label for="test7" style="font-size: 15px">女</label>
                                        </div><!--/.form-group -->
                                        <div class="form-group">
                                            <label for="age" style="font-size: 20px">年龄</label>
                                            <input type="text" name="dsum" class="form-control" id="age" >
                                        </div><!--/.form-group -->
                                        <div class="form-group">
                                            <label for="phone"style="font-size: 20px">电话号码</label>
                                            <input type="text" name="dname" class="form-control" id="phone" >
                                        </div><!--/.form-group -->
                                        <div class="form-group">
                                            <label for="idcard"style="font-size: 20px">身份证号</label>
                                            <input type="text" name="dsum" class="form-control" id="idcard" >
                                        </div><!--/.form-group -->
                                        <div class="form-group">
                                            <label for="email"style="font-size: 20px">email</label>
                                            <input type="text" name="dname" class="form-control" id="email" >
                                        </div><!--/.form-group -->
                                        <div class="form-group">
                                            <label for="addres"style="font-size: 20px">地址</label>
                                            <input type="text" name="dsum" class="form-control" id="addres" >
                                        </div><!--/.form-group -->
                                        <div class="form-group">
                                            <label for="account"style="font-size: 20px">账号</label>
                                            <input type="text" name="dname" class="form-control" id="account" >
                                        </div><!--/.form-group -->
                                        <div class="form-group">
                                            <label for="password"style="font-size: 20px">密码</label>
                                            <input type="text" name="dsum" class="form-control" id="password" >
                                        </div><!--/.form-group -->
                                        <button type="submit" id="add" class="btn signin_btn" data-toggle="modal" data-target=".signin_modal">
                                            保存
                                        </button>
                                    </div>
                                    </form><!--/form -->
                                </div><!--/.col -->
                            </div><!--/.row -->

                        </div><!--/.signin-form -->

                    </div><!--/.modal-body -->

                </div><!--/.sign-content -->
            </div><!--/.modal-content -->
        </div><!--/.modal-dialog -->
    </div><!--/.modal -->
</div>

<!-- /. PAGE WRAPPER  -->
<!-- /. WRAPPER  -->
<!-- JS Scripts-->

#  表格
    <script>
        $.ajax({
            url: "/selectDeptList",
            async: false,
            type: "get",
            dataType: "json",
            success:function (data){
                console.log(data)
                for (let i=0;i<data.length;i++){
                    $("[name=signin_aintodepts1]").
                    append("<option  name='d' value="+data[i].did+">"+data[i].dname+"</option>")
                }
            }
        })
        $.ajax({
            url: "/selectDeptList",
            async: false,
            type: "get",
            dataType: "json",
            success:function (data){
                console.log(data)
                for (let i=0;i<data.length;i++){
                    $("[name=signin_aintodepts2]").
                    append("<option  name='dd' value="+data[i].did+">"+data[i].dname+"</option>")
                }
            }
        })
        $.ajax({
            url: "/selectDeptList",
            async: false,
            type: "get",
            dataType: "json",
            success:function (data){
                console.log(data)
                for (let i=0;i<data.length;i++){
                    $("[name=signin_aintodepts]").
                    append("<option  name='ddd' value="+data[i].did+">"+data[i].dname+"</option>")
                }
            }
        })
        $("#check").click(function () {
            $.ajax({
                    url: "/selectUserByCheck",
                    dataType: "json",
                    type: "post",
                    data:{
                        username:$("#checkid").val(),
                        account:$("#checkname").val(),
                        did:$("[name=ddd]:selected").val(),
                        sex:$("[name=sexss]:checked").val()
                    },
                success:function (data) {
                    $("[name=deptTable]").empty();
                    var rolee = null;
                    var dept=null;
                    for (var i = 0;i<data.length;i++){
                        $.ajax({
                            url:"/getRolebyId",
                            //请求方式
                            type:"POST",
                            //数据形式
                            async:false,
                            dataType:"json",
                            data:{
                                rid:data[i].rid
                            },
                            //请求成功后调用的回调函数
                            success:function (result) {
                                rolee=result.rname;
                            }
                        })
                        $.ajax({
                            url:"/getDeptByDid",
                            //请求方式
                            type:"POST",
                            //数据形式
                            async:false,
                            dataType:"json",
                            data:{
                                did:data[i].did
                            },
                            //请求成功后调用的回调函数
                            success:function (result) {
                                dept=result.dname;
                            }
                        })
                        $("[name=deptTable]").append(
                            "<tr class=\"gradeU\">\n"+
                            "   <td>"+ data[i].id+ "</td>\n"+
                            "   <td>"+ data[i].username+ "</td>\n"+
                            "    <td>"+ rolee+ "</td>\n"+
                            "    <td>"+ dept+ "</td>\n"+
                            "    <td>"+ data[i].sex+ "</td>\n"+
                            "    <td>"+ data[i].age+ "</td>\n"+
                            "    <td>"+ data[i].phone+ "</td>\n"+
                            "    <td>"+ data[i].idcard+ "</td>\n"+
                            "    <td>"+ data[i].email+ "</td>\n"+
                            "    <td>"+ data[i].address+ "</td>\n"+
                            "    <td>"+ data[i].account+ "</td>\n"+
                            "    <td>"+ data[i].password+ "</td>\n"+
                            "   <td>\n"+
                            "    <button class=btn signin_btn data-toggle=modal data-target=.update onclick=update("+data[i].account+")>编辑<tton>\n"+
                            "     <button class=btn signin_btn data-toggle=modal onclick=del("+data[i].id+")>删除<tton>\n"+
                            "     </td>\n"+
                            "     </tr>"
                        );
                    }
                }
                }
            )

        })

    var dname = $("#dname").val();
    var dsum = $("#dsum").val();


    $(function(){
        $.ajax({
            url:"/selectuser",
            //请求方式
            type:"POST",
            //数据形式
            dataType:"json",
            async:false,
            //请求成功后调用的回调函数
            success:function (data) {

                var rolee = null;
                var dept=null;
                for (var i = 0;i<data.length;i++){
                    var sex=null;
                    if(data[i].sex==1){
                        sex='男';
                    }else{
                        sex='女';
                    }
                    $.ajax({
                        url:"/getRolebyId",
                        //请求方式
                        type:"POST",
                        //数据形式
                        async:false,
                        dataType:"json",
                        data:{
                          rid:data[i].rid
                        },
                        //请求成功后调用的回调函数
                        success:function (result) {
                        rolee=result.rname;
                        }
                    })
                    $.ajax({
                        url:"/getDeptByDid",
                        //请求方式
                        type:"POST",
                        //数据形式
                        async:false,
                        dataType:"json",
                        data:{
                            did:data[i].did
                        },
                        //请求成功后调用的回调函数
                        success:function (result) {
                            dept=result.dname;
                        }
                    })
                    $("[name=deptTable]").append(
                        "<tr class=\"gradeU\">\n"+
                        "   <td>"+ data[i].id+ "</td>\n"+
                        "   <td>"+ data[i].username+ "</td>\n"+
                        "    <td>"+ rolee+ "</td>\n"+
                        "    <td>"+ dept+ "</td>\n"+
                        "    <td>"+sex+ "</td>\n"+
                        "    <td>"+ data[i].age+ "</td>\n"+
                        "    <td>"+ data[i].phone+ "</td>\n"+
                        "    <td>"+ data[i].idcard+ "</td>\n"+
                        "    <td>"+ data[i].email+ "</td>\n"+
                        "    <td>"+ data[i].address+ "</td>\n"+
                        "    <td>"+ data[i].account+ "</td>\n"+
                        "    <td>"+ data[i].password+ "</td>\n"+
                        "   <td>\n"+
                        "    <button class=btn signin_btn data-toggle=modal data-target=.update onclick=update("+data[i].account+")>编辑<tton>\n"+
                        "     <button class=btn signin_btn data-toggle=modal  onclick=del("+data[i].id+")>删除<tton>\n"+
                        "     </td>\n"+
                        "     </tr>"
                    );
                }
            }
        })
    })


    function update(account){

        $.ajax({
            url:"/getUserById",
            type:"post",
            data:{
                account:account
            },
            dataType:"json",
            success:function (data) {
                $('#assetList').empty();
                document.getElementById("upid").value=data.id;
                document.getElementById("upusername").value = data.username;
                // document.getElementById("uprid").value = data.rid;
                document.getElementsByName("sex").value = data.sex;
                document.getElementById("upage").value = data.age;
                document.getElementById("upphone").value = data.phone;
                document.getElementById("upidcard").value = data.idcard;
                document.getElementById("upemail").value = data.email;
                document.getElementById("upaddres").value = data.address;
                document.getElementById("upaccount").value = data.account;
                document.getElementById("uppassword").value = data.password;
                console.log(data)
            }
        })
    }

    var phoneNumReg = /^1[3|4|5|7|8]\d{9}$/;
    var idCardRegex = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    $(function(){
        $.ajax({
            url:"/selectRoles",
            dataType:"json",
            type:"post",
            success:function (data) {
                for (var i=0;i<data.length;i++){
                    $("[name=signin]").append(" <option value='"+data[i].rid+"' name='sss'>"+data[i].rname+"</option>")
                }
            },
            default:function () {
                alert("123")
            }
        })
    })
        $(function(){
            $.ajax({
                url:"/selectRoles",
                dataType:"json",
                type:"post",
                success:function (data) {
                    for (var i=0;i<data.length;i++){
                        $("[name=signin1]").append(" <option value='"+data[i].rid+"' name='ss'>"+data[i].rname+"</option>")
                    }
                }
            })
        })


    $("#add").click(function () {

        if($("#username").val()==null||
            $("[name=d]:selected").val()==null||
            $("[name=sss]:selected").val()==null||
            $("[name=sexxx]:checked").val()==null||
            $("#age").val()==null||
           $("#phone").val()==null||
            $("#idcard").val()==null||
           $("#email").val()==null||
            $("#addres").val()==null||
            $("#account").val()==null||
           $("#password").val()==null){
            alert("信息不能为空，请重新输入");
        }else if(!idCardRegex.test(document.getElementById("idcard").value)){
            alert("身份证号不正确")
        }else if(!phoneNumReg.test(document.getElementById("phone").value)){
            alert("电话号码不正确")
        }else{
            alert( $("[name=sss]:selected").val());
            $.ajax({
                    url:"/adduser",
                    data:{
                          username:$("#username").val(),
                          rid:$("[name=sss]:selected").val(),
                          sex:$("#sex").val(),
                          age:$("[name=sexxx]:checked").val(),
                          phone:$("#phone").val(),
                          idcard:$("#idcard").val(),
                          email:$("#email").val(),
                          address:$("#addres").val(),
                          account:$("#account").val(),
                          password:$("#password").val(),
                          did:$("[name=d]:selected").val()
                    },
                    type:"post",
                    dataType:"json",
                    success:function (data) {
                        if(data == "2"){
                            alert("账号已存在")
                        }else if(data=="1"){
                            alert("添加成功")
                            location.href="/jsp/user.jsp";
                        }else if(data==""){
                            alert("已存在该用户")
                        }
                    }
                }
            )
        }
    })

    $("#update").click(function () {
        if($("#upusername").val()==null||
            $("[name=ss]:selected").val()==null||
            $("[name=sexx]:checked").val()==null||
            $("#upage").val()==null||
            $("#upphone").val()==null||
            $("#upidcard").val()==null||
            $("#upemail").val()==null||
            $("#upaddres").val()==null||
            $("#upaccount").val()==null||
            $("#uppassword").val()==null||
            $("[name=dd]:selected").val()==null){
            alert("信息不能为空，请重新输入");
        }else
            if(!idCardRegex.test(document.getElementById("upidcard").value)){
            alert("身份证号不正确")
        }else if(!phoneNumReg.test(document.getElementById("upphone").value)){
            alert("电话号码不正确")
        }else{
            $.ajax({
                    url:"/updateUser",
                    data:{
                        username:$("#upusername").val(),
                        rid: $("[name=ss]:selected").val(),
                        sex:$("[name=sexx]:checked").val(),
                        age:$("#upage").val(),
                        phone:$("#upphone").val(),
                        idcard:$("#upidcard").val(),
                        email:$("#upemail").val(),
                        address:$("#upaddres").val(),
                        account:$("#upaccount").val(),
                        password:$("#uppassword").val(),
                        id:$("#upid").val(),
                        did:$("[name=dd]:selected").val()
                    },
                    type:"post",
                    dataType:"json",
                    success:function (data) {
                        console.log(data);
                        if(data == "2"){
                            alert("账号已存在")
                        }else if(data=="1"){
                            alert("修改成功")
                            location.href="/jsp/user.jsp";
                        }else if(data==""){
                            alert("已存在该用户")
                        }
                    }
                }
            )
        }
    })


    function del(iou){
        var r = confirm("确定删除此条数据？");
        if (r == true) {
            $.ajax({
                url:"/deleteUserById",
                data:{
                    id:iou
                },
                type:"post",
                dataType:"json",
                success:function (data) {
                    console.log(data);
                    if(data != 0){
                        alert("删成功除！");
                        location.href="/jsp/user.jsp";
                    }else{
                        alert("删除失败");
                        location.href="/jsp/user.jsp";
                    }
                }
            })
        }else{
            r = false;
        }
    }



</script>

<!-- jQuery Js -->
<script src="/resource/js/jquery-1.10.2.js"></script>

<!-- Bootstrap Js -->
<script src="/resource/js/bootstrap.min.js"></script>

<script src="/resource/materialize/js/materialize.min.js"></script>

<!-- Metis Menu Js -->
<script src="/resource/js/jquery.metisMenu.js"></script>
<!-- Morris Chart Js -->
<script src="/resource/js/morris/raphael-2.1.0.min.js"></script>
<script src="/resource/js/morris/morris.js"></script>


<script src="/resource/js/easypiechart.js"></script>
<script src="/resource/js/easypiechart-data.js"></script>

<script src="/resource/js/Lightweight-Chart/jquery.chart.js"></script>
<!-- DATA TABLE SCRIPTS -->
<script src="/resource/js/dataTables/jquery.dataTables.js"></script>
<script src="/resource/js/dataTables/dataTables.bootstrap.js"></script>
<script>
    $(document).ready(function () {
        $('#dataTables-example').dataTable();
    });
</script>
<!-- Custom Js -->
<script src="/resource/js/custom-scripts.js"></script>


</div>
</body>

</html>

